const wsUri = "ws://127.0.0.1:22003";
let websocket;

function doSend(message) {
    websocket.send(message);
}


export function websopen({onMessage, onOpen, onClose, onError}) {
    websocket = new WebSocket(wsUri);
    websocket.onopen = function () {
        onOpen()
    };
    websocket.onclose = function () {
        onClose()
    };
    websocket.onmessage = function (evt) {
        onMessage(evt)
    };
    websocket.onerror = function () {
        onError()
    };
}

export function websclose() {
    websocket.close();
}

// 启动设备
export function opendev() {
    var str = "{\"module\":\"fingerprint\",\"function\":\"open\",\"msgid\":\"123456789\",\"parameter\":\"\"}"
    doSend(str);
}
// 启动采集
export function register() {
    doSend("{\"module\":\"fingerprint\",\"function\":\"register\",\"msgid\":\"123456789\",\"parameter\":\"\"}");
}
// 取消采集
export function disregister() {
    doSend("{\"module\":\"fingerprint\",\"function\":\"cancelregister\",\"msgid\":\"123456789\",\"parameter\":\"\"}");
}
// 关闭设备
export function closedev() {
    doSend("{\"module\":\"fingerprint\",\"function\":\"close\",\"msgid\":\"123456789\",\"parameter\":\"\"}");
}